﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SharingCenter.Web.Shared
{
    using SharingCenter.Web.Classes;
    public partial class AlbumOrganize : System.Web.UI.UserControl
    {
        protected static Guid albumId;
        protected List<Sc_AlbumImage> imageToUpdate;
        Sc_AlbumImage tmpImage;
        public event EventHandler<EventArgs> AlbumUpdated;

        public Guid AlbumId
        {
            get { return albumId; }
            set { albumId = value; }
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            ListView1.ItemUpdating += new EventHandler<ListViewUpdateEventArgs>(ListView1_ItemUpdating);
            LinqDataSource1.Selecting += new EventHandler<LinqDataSourceSelectEventArgs>(LinqDataSource1_Selecting);
        }

        void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            e.WhereParameters["AlbumId"] = albumId;
        }

        void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            if (e.NewValues["Title"] != e.OldValues["Title"])
            {
                imageToUpdate.Add(tmpImage);
            }
        }

        public void UpdateAlbum()
        {
            imageToUpdate = new List<Sc_AlbumImage>();
            foreach (ListViewDataItem item in ListView1.Items)
            {
                //imageToUpdate.Add((Sc_AlbumImage)item.DataItem);
                ListView1.UpdateItem(item.DataItemIndex, true);
            }
            AlbumUpdated(this, new EventArgs());
        }
    }
}